package org.fang;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @Author forsake
 * @Description
 * @SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})代表数据库自动注入，加了会报错
 * @Date 17:25 2022/3/9
 **/
@SpringBootApplication
@EnableEurekaClient
// 扫描feign的service
@EnableFeignClients(basePackages = {"org.fang.service"})
@EnableDiscoveryClient // 获取服务信息
//添加对熔断的支持
@EnableCircuitBreaker
public class CloudProviderHystrix_8004 {
    public static void main(String[] args) {
        ConfigurableApplicationContext run = SpringApplication.run(CloudProviderHystrix_8004.class, args);
    }

    /**
     * 只有存在熔断注解    @HystrixCommand(fallbackMethod = "hystrixGet")的服务才能监控，否则只有http://localhost:8004/actuator/hystrix.stream页面只有ping，没有data，
     * @return
     */
    @Bean
    public ServletRegistrationBean HystrixMetricsStreamServlet() {
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new HystrixMetricsStreamServlet());
        servletRegistrationBean.addUrlMappings("/actuator/hystrix.stream");
        return servletRegistrationBean;
    }
}
